from SoAnalyser import SoAnalyser
import argparse
# pkg_name = ""
# depend_pkg_name = "libc6_2.23-0ubuntu11.3_amd64"
# pkg_dir = "./"
# depend_pkg_funcs = SoAnalyser.analyse_so_elf("./libarchive13_3.2.1-2~ubuntu16.04.1_amd64/libarchive.so.13.2.1")["provide"]
# require_pkg_funcs = SoAnalyser.analyse_so_elf("./libarchive-tools_3.2.1-2~ubuntu16.04.1_amd64/bsdcat")["require"]
provide_pkg_dir = "./libarchive13_3.2.1-2~ubuntu16.04.1_amd64"
require_pkg_dir = "./libarchive-tools_3.2.1-2~ubuntu16.04.1_amd64"
backup_provide_pkg_dir = "./libc6_2.23-0ubuntu11.3_amd64"

# 根据readelf的结果获取文件符号表信息，
# 分析两个软件包之间的函数依赖数
if __name__ =="__main__":
    provide_pkg_id = "libarchive13_3.2.1-2~ubuntu16.04.1_amd64"
    require_pkg_id = "libarchive-tools_3.2.1-2~ubuntu16.04.1_amd64"
    parser = argparse.ArgumentParser()  # 创建一个解析对象
    parser.add_argument('-p', '--provide_pkg_id', default=provide_pkg_id)
    parser.add_argument('-r', '--require_pkg_id', default=require_pkg_id)
    args = parser.parse_args()

    depend_funcs_set = SoAnalyser.find_depend_func_num("./" + args.provide_pkg_id, "./" + args.require_pkg_id)
    depend_funcs_2str = '\n    '.join(depend_funcs_set)
    print(f"{require_pkg_id} --[:Depends On]-> {provide_pkg_dir}'s functions are: ")
    print(f"    {depend_funcs_2str}")
    print(f"{require_pkg_id} --[:Depends On]-> {provide_pkg_dir}'s functions numbers:\n    {len(depend_funcs_set)}")





# analyse_pkg_func(depend_pkg_name)